package service.impl.v2;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;

import dao.v2.ConfigVOMapper;
import dao.v2.MemberTicketVOMapper;
import dao.v2.MemberVOMapper;
import dao.v2.MessageVOMapper;
import dao.v2.OrderVOMapper;
import model.LogEarnVO;
import model.MemberVO;
import model.OrderPayVO;
import model.OrderVO;
import service.v2.ConfigService;
import service.v2.MemberService;
import service.v2.MoneyService;
import service.v2.OrderService;
import service.v2.PushService;
import service.v2.WeChatService;
import service.v2.WechatLoginService;
import util.NumberUtil;
import util.PushUtil;
import util.WeixinUtil;
@Service
public class PushServiceImpl implements PushService {
	
	@Autowired
	private MemberVOMapper memberDao;
	@Autowired
	private WeChatService wechatservice;
	@Autowired
	private ConfigVOMapper configvomapper;
	@Autowired
	private MemberService memberService;
	@Autowired
	private MemberTicketVOMapper memberTicketVOMapper;
	@Autowired
	private MoneyService moneyService;
	@Autowired
	private OrderService orderService;
	@Autowired
	private OrderVOMapper orderVOMapper;
	@Autowired
	private MessageVOMapper msgDao;
	/*
	 *成功邀请下线 公众号推送
	 */
	public void pushInvitedByMsg(MemberVO memberVO) {
		MemberVO vo=memberDao.getAllInfoById(memberVO.getId());
		final String  open_id = vo.getPush_open_id();
		final String  nick_name = vo.getNick_name();
		
		final String invited_by = vo.getInvited_by();
		if(invited_by !=null){
			new Thread(new Runnable() {
				public void run() {
					MemberVO s_vo=memberDao.getSxMemberVOInfo(invited_by);	
					String content ="【邀请成功】已成功邀请"+nick_name+"加入您的团队。";
					wechatservice.sendWeChatMsgCommonMethod(s_vo.getId(),content);
				}
			}).start();
		}
	}
	/*
	 *修改邀请人 公众号推送
	 */
	public void pushChangeInvitedByMsg(MemberVO memberVO) {
		final String  invited_by = memberVO.getInvited_by();
		final String  open_id = memberVO.getPush_open_id();
		final String  nick_name= memberVO.getNick_name();
		
		new Thread(new Runnable() {
			public void run() {
				if(invited_by!=null){
					String access_token = wechatservice.getAccessToken();
					MemberVO s_vo=memberDao.getSxMemberVOInfo(invited_by);
					if(open_id!=null){
						String x_nickname = WeixinUtil.getWeChatInfo(access_token,open_id);
						if(!"nickname_err".equals(x_nickname)){
							String content3 ="【邀请成功】已成功邀请"+x_nickname+"加入您的团队。";
							wechatservice.sendWeChatMsgCommonMethod(s_vo.getId(),content3);
						}
					}else{
						String content4 ="【邀请成功】已成功邀请"+nick_name+"加入您的团队。";
						wechatservice.sendWeChatMsgCommonMethod(s_vo.getId(),content4);
					}
				}
			}
		}).start();
		
	}
	/*
	 *订单已被取消 个推
	 */
	public void sendCancelOrderPush(String member_id, String order_no) {
		final String  memberId = member_id;
		final String  orderNo = order_no;
		final String app_logo = configvomapper.loadConfig("APP_LOGO");
		final String app_name = configvomapper.loadConfig("APP_NAME");	
		final String push_id = memberService.getCidById(memberId);	
		
		
		new Thread(new Runnable() {
			public void run() {
				Map<String, Comparable> map = new HashMap<String, Comparable>();
				map.put("title", app_name);
				map.put("content", "订单"+orderNo+"已取消");
				map.put("type", 5);
				
				PushUtil.getuiPushSingle(push_id,app_logo,app_name,
						"订单"+orderNo+"已取消", "",JSON.toJSONString(map));
			}
		}).start();
		
	}
	/*
	 *余额充值 公众号推送
	 */
	public void pushBalanceRecharge(MemberVO membervo, OrderPayVO payVO) {
		final String  free_cash = membervo.getFree_cash();
		final String  total_price = payVO.getTotal_price();
		final String wechat_host = configvomapper.loadConfig("WECHAT_HOST");
		final String member_id = membervo.getId();
		
		new Thread(new Runnable() {
			public void run() {
				
			StringBuffer buffer = new StringBuffer();
			buffer.append("账户充值").append("\n\n");	
			buffer.append("恭喜您成功充值：￥"+total_price).append("\n");	
			buffer.append("充值后余额：￥"+free_cash).append("\n\n");	
			buffer.append("<a href=\""+wechat_host+"/account_account\">>>点击查看我的账户余额</a>");	
			String content =buffer.toString();
			wechatservice.sendWeChatMsgCommonMethod(member_id,content);
			}
		}).start();
		
	}
	/*
	 *电子提货券购买 公众号推送
	 */
	public void pushMemberTicket(String member_id, String rate, String ticket) {
		final String memberId = member_id;
		final String rate_ = rate;
		final String ticket_ = ticket;
		final String wechat_host = configvomapper.loadConfig("WECHAT_HOST");
		final String ticket_name = configvomapper.loadConfig("TICKET_NAME");
		final int use_tickets=memberTicketVOMapper.selectUseTickets(memberId);	
		
		new Thread(new Runnable() {
			public void run() {
			
			StringBuffer buffer = new StringBuffer();
			buffer.append(ticket_name+"购买！").append("\n\n");	
			double rate1 =Double.parseDouble(rate_);
			String rate2=rate_;
			//小数点处理 不到1元进一
			if(rate1<1 && rate1>0){
				rate1=rate1*10;
				buffer.append("恭喜您成功购买 "+ticket_+ticket_name+"("+rate1+"折)").append("\n");	
			}else{
				rate2=(NumberUtil.formatDouble((int)rate1,0));
				buffer.append("恭喜您成功购买 "+ticket_+"("+rate2+"折)").append("\n");	
			}
			buffer.append("可交易"+ticket_name+"余额："+use_tickets).append("\n\n");	
			buffer.append("<a href=\""+wechat_host+"/ticket_ticket\">>>点击查看我的"+ticket_name+"</a>");	
			String content_ =buffer.toString();
			
			wechatservice.sendWeChatMsgCommonMethod(memberId,content_);
			System.out.println("电子提货券购买 公众号推送");
			}
		}).start();
		
	}
	
	/*
	 *您新收到了一个赞
	 */
	public void praiseInsertSub(String push_id) {
		final String pushId = push_id;
		new Thread(new Runnable() {
			public void run() {
				Map<String, Comparable> map = new HashMap<String, Comparable>();
				map.put("title", configvomapper.loadConfig("APP_NAME"));
				map.put("content", "您收到了新的赞");
				map.put("type", 4);
				PushUtil.getuiPushSingle(pushId, configvomapper.loadConfig("APP_LOGO"),  configvomapper.loadConfig("APP_NAME"), "您收到了新的赞", "", JSON.toJSONString(map));
			}
		}).start();
	}
	/*
	 *您新收到了一个赞
	 */
	public void pushwindowCommentInsertSub(String push_id) {
		final String pushId = push_id;
		final String app_logo = configvomapper.loadConfig("APP_LOGO");
		final String app_name = configvomapper.loadConfig("APP_NAME");
		
		new Thread(new Runnable() {
			public void run() {
				Map<String, Comparable> map = new HashMap<String, Comparable>();
				map.put("title", app_name);
				map.put("content", "您收到了新的评论");
				map.put("type", 4);
				PushUtil.getuiPushSingle(pushId, app_logo,  app_name, "您收到了新的评论", "", JSON.toJSONString(map));
			}
		}).start();
		
	}
	/*
	 * 评论回复 >您收到了新的评论
	 */
	public void pushWindowCommentReply(String push_id) {
		final String pushId = push_id;
		final String app_logo = configvomapper.loadConfig("APP_LOGO");
		final String app_name = configvomapper.loadConfig("APP_NAME");
		
		new Thread(new Runnable() {
			public void run() {
				Map<String, Comparable> map = new HashMap<String, Comparable>();
				map.put("title", app_name);
				map.put("content", "您收到了新的评论");
				map.put("type", 4);
				PushUtil.getuiPushSingle(pushId, app_logo, app_name, "您收到了新的评论", "", JSON.toJSONString(map));
			}
		}).start();
		
	}
	/*
	 * 评论回复回复 >您收到了新的评论
	 */
	public void pushWindowCommentReplyBack(String push_id) {
		final String pushId = push_id;
		final String app_logo = configvomapper.loadConfig("APP_LOGO");
		final String app_name = configvomapper.loadConfig("APP_NAME");
		
		new Thread(new Runnable() {
			public void run() {
				Map<String, Comparable> map = new HashMap<String, Comparable>();
				map.put("title", app_name);
				map.put("content", "您收到了新的评论");
				map.put("type", 4);
				PushUtil.getuiPushSingle(pushId, app_logo, app_name, "您收到了新的评论", "", JSON.toJSONString(map));
			}
		}).start();
		
	}
	/*
	 * 电子提货券充值 分润推送   个推&公众号
	 */
	public void rechargeTicket(String conn_no,String member_id) {
		final String connNo = conn_no;
		final String wechat_host = configvomapper.loadConfig("WECHAT_HOST");
		final String member_id_ = member_id;
		final String app_logo = configvomapper.loadConfig("APP_LOGO");
		final String app_name = configvomapper.loadConfig("APP_NAME");
		final List<String> member_list =  memberService.getShangXianMemberId(connNo);

		//个推
		new Thread(new Runnable() {
			public void run() {
				if(member_list.size()!=0){
					for(int i=0;i<member_list.size();i++){
						if(member_list.get(i)!=null){
							List<LogEarnVO> list = moneyService.selectRechargeTicketAwardList(member_list.get(i),connNo);//
							for(int j=0; j<list.size();j++){
								Map<String, Comparable> map = new HashMap<String, Comparable>();
								map.put("title", app_name);
								map.put("content", "您有一笔" + list.get(j).getEarn_money()+ "元收入");
								map.put("type", 2);
								PushUtil.getuiPushSingle(member_list.get(i), app_logo,app_name,
										"您有一笔" + list.get(j).getEarn_money()+ "元收入", "",JSON.toJSONString(map));
								//消息+1
								msgDao.updMemberMsg(member_list.get(i), "4");
								System.out.println("电子提货券充值 分润推送  个推");
							}
						}
					}
				}
			}
		}).start();
		//公众号 
		new Thread(new Runnable() {
			public void run() {
				String nick_name = memberService.getNickName(member_id_);
				if(member_list.size()!=0){
					for(int i=0;i<member_list.size();i++){
						if(member_list.get(i)!=null){
							List<LogEarnVO> list = moneyService.selectRechargeTicketAwardList(member_list.get(i),connNo);//
							for(int j=0; j<list.size();j++){
								StringBuffer buffer = new StringBuffer();
								if(("2".equals(list.get(j).getAward())) || (list.get(j).getAward().indexOf("3,2")>-1) ||(list.get(j).getAward().indexOf("2,3")>-1) ){
									//活力奖（2）+助理奖（3）
									buffer.append("您有一笔收益！").append("\n\n");	
									buffer.append("交易类型："+list.get(j).getAward_name()).append("\n");	
									buffer.append("对方账号："+nick_name).append("\n");	
									buffer.append("获得收益：￥"+list.get(j).getEarn_money()
											+"(本金￥"+list.get(j).getCapital_cash()
											+"+利润￥"+list.get(j).getProfit_cash()
											+"+购物专用金￥"+list.get(j).getBuy_cash()+")").append("\n\n");	
									buffer.append("<a href=\""+wechat_host+"/account_cash\">>>查看详情</a>");	
									String content =buffer.toString();
									wechatservice.sendWeChatMsgCommonMethod(member_list.get(i),content);
								}else if("4".equals(list.get(j).getAward())){
									buffer.append("您有一笔收益！").append("\n\n");	
									buffer.append("交易类型："+list.get(j).getAward_name()).append("\n");	
									buffer.append("对方账号："+nick_name).append("\n");	
									buffer.append("获得收益：￥"+list.get(j).getEarn_money()
											+"(利润￥"+list.get(j).getProfit_cash()
											+"+购物专用金￥"+list.get(j).getBuy_cash()+")").append("\n\n");	
									buffer.append("<a href=\""+wechat_host+"/account_cash\">>>查看详情</a>");	
									String content =buffer.toString();
									wechatservice.sendWeChatMsgCommonMethod(member_list.get(i),content);
								}else{
									buffer.append("您有一笔收益！").append("\n\n");	
									buffer.append("交易类型："+list.get(j).getAward_name()).append("\n");	
									buffer.append("对方账号："+nick_name).append("\n");	
									buffer.append("获得收益：￥"+list.get(j).getEarn_money()).append("\n\n");	
									buffer.append("<a href=\""+wechat_host+"/account_cash\">>>查看详情</a>");	
									String content =buffer.toString();
									wechatservice.sendWeChatMsgCommonMethod(member_list.get(i),content);
								}
								System.out.println("电子提货券充值 分润推送  公众号");
							}
						}
					}
				}
			}
		}).start();
		
	}
	/*
	 * 订单支付推送  公众号
	 */
	public void pushOrderPay(List<OrderVO> orderList) {
		final String app_name = configvomapper.loadConfig("APP_NAME");
		final String wechat_host = configvomapper.loadConfig("WECHAT_HOST");
		final String ticket_name = configvomapper.loadConfig("TICKET_NAME");

		new Thread(new Runnable() {
			public void run() {
				for(int i=0;i<orderList.size();i++){
					OrderVO orderVO=orderList.get(i);
					String good_name= orderService.getOrderGoodName(orderVO.getId());
					DecimalFormat  df = new DecimalFormat("######0.00");   

					StringBuffer buffer = new StringBuffer();
					buffer.append("【"+app_name+"】订单支付成功！").append("\n\n");	
					//现金+商票
					if(!"0".equals(orderVO.getTotal_price())&&!"0".equals(orderVO.getTotal_ticket())){
						String total_price =df.format(Double.parseDouble(orderVO.getTotal_price())+Double.parseDouble(orderVO.getFreight()));
						buffer.append("订单金额：￥"+total_price+"+"+orderVO.getTotal_ticket()+ticket_name).append("\n");	
					}
					//现金
					if(!"0".equals(orderVO.getTotal_price())&&"0".equals(orderVO.getTotal_ticket())){
						String total_price =df.format(Double.parseDouble(orderVO.getTotal_price())+Double.parseDouble(orderVO.getFreight()));
						buffer.append("订单金额：￥"+total_price).append("\n");	
					}
					//商票
					if("0".equals(orderVO.getTotal_price())&&!"0".equals(orderVO.getTotal_ticket())){
						buffer.append("订单金额："+orderVO.getTotal_ticket()+ticket_name).append("\n");	
					}
					if(good_name.length()>15){
						good_name = good_name.substring(0, 14)+"...";
						buffer.append("购买商品："+good_name).append("\n");	
					}else{
						buffer.append("购买商品："+good_name).append("\n");	
					}
					buffer.append("收货信息："+orderVO.getAddress_name()+","+orderVO.getAddress_tel()+","+orderVO.getAddress_content()).append("\n");	
					buffer.append("订单编号："+orderVO.getNo()).append("\n\n");	
					buffer.append("<a href=\""+wechat_host+"/orderDetail?order_id="+orderVO.getId()+"\">>>查看详情</a>");	
					String content =buffer.toString();
					wechatservice.sendWeChatMsgCommonMethod(orderVO.getCreate_by(),content);
				}
			}
		}).start();
	}
	/*
	 * 只买东西时分润推送
	 */
	public void BuyGoodsProfit(String orderId) {
		final String wechat_host = configvomapper.loadConfig("WECHAT_HOST");
		final String app_logo = configvomapper.loadConfig("APP_LOGO");
		final String app_name = configvomapper.loadConfig("APP_NAME");
		final String order_id = orderId;
		final OrderVO orderVO = orderVOMapper.getOrderById(order_id);
		final String nick_name=memberService.getNickName(orderVO.getCreate_by());
		
		List<String> member_list =memberService.getShangXianMemberIdByOrderId(orderId);
		if(member_list.size()!=0){
			for(int i=0;i<member_list.size();i++){
				if(member_list.get(i)!=null){
					final List<LogEarnVO> list =(ArrayList<LogEarnVO>) moneyService.selectBuyGoodsProfitAwardList(member_list.get(i),orderId);//
					//个推
					final String memberId=member_list.get(i);
					new Thread(new Runnable() {
						public void run() {
							if("3".equals(orderVO.getState()) || "4".equals(orderVO.getState())){
								for(int j=0; j<list.size();j++){
									Map<String, Comparable> map = new HashMap<String, Comparable>();
									map.put("title", app_name);
									map.put("content", "您有一笔" + list.get(j).getEarn_money()+ "元收入");
									map.put("type", 2);
									PushUtil.getuiPushSingle(memberId, app_logo,app_name,
											"您有一笔" + list.get(j).getEarn_money()+ "元收入", "",JSON.toJSONString(map));
									//消息+1
									msgDao.updMemberMsg(memberId, "4");
									System.out.println("只买东西时分润推送 个推");
								}
							}
						}
					}).start();
					
					//公众号
					new Thread(new Runnable() {
						public void run() {
							if("3".equals(orderVO.getState()) || "4".equals(orderVO.getState())){
								for(int  j=0; j<list.size();j++){
									StringBuffer buffer = new StringBuffer();
									if((list.get(j).getAward().indexOf("3,2")>-1) ||(list.get(j).getAward().indexOf("2,3")>-1) ||"2".equals(list.get(j).getAward())){
										//活力奖（2）+助理奖（3）
										buffer.append("您有一笔收益！").append("\n\n");	
										buffer.append("交易类型："+list.get(j).getAward_name()+"(待结算)").append("\n");	
										buffer.append("对方账号："+nick_name).append("\n");	
										buffer.append("获得收益：￥"+list.get(j).getEarn_money()
												+"(本金￥"+list.get(j).getCapital_cash()
												+"+利润￥"+list.get(j).getProfit_cash()
												+"+购物专用金￥"+list.get(j).getBuy_cash()+")").append("\n\n");	
										buffer.append("<a href=\""+wechat_host+"/account_waitCash\">>>查看详情</a>");	
										String content =buffer.toString();
										wechatservice.sendWeChatMsgCommonMethod(memberId,content);
									}else if("4".equals(list.get(j).getAward())){
										buffer.append("您有一笔收益！").append("\n\n");	
										buffer.append("交易类型："+list.get(j).getAward_name()+"(待结算)").append("\n");	
										buffer.append("对方账号："+nick_name).append("\n");	
										buffer.append("获得收益：￥"+list.get(j).getEarn_money()
												+"(利润￥"+list.get(j).getProfit_cash()
												+"+购物专用金￥"+list.get(j).getBuy_cash()+")").append("\n\n");	
										buffer.append("<a href=\""+wechat_host+"/account_waitCash\">>>查看详情</a>");	
										String content =buffer.toString();
										wechatservice.sendWeChatMsgCommonMethod(memberId,content);
									}else{
										buffer.append("您有一笔收益！").append("\n\n");	
										buffer.append("交易类型："+list.get(j).getAward_name()+"(待结算)").append("\n");	
										buffer.append("对方账号："+nick_name).append("\n");	
										buffer.append("获得收益：￥"+list.get(j).getEarn_money()).append("\n\n");	
										buffer.append("<a href=\""+wechat_host+"/account_waitCash\">>>查看详情</a>");	
										String content =buffer.toString();
										wechatservice.sendWeChatMsgCommonMethod(memberId,content);
									}
									System.out.println("只买东西时分润推送 公众号");
								}
							}
						}
					}).start();
				}
			}
		}
	}
	/*
	 * 买套餐分润推送 (商品)
	 */
	public void BuyGoodsPackageProfitByOrderId(String orderId) {
		final String wechat_host = configvomapper.loadConfig("WECHAT_HOST");
		final String app_logo = configvomapper.loadConfig("APP_LOGO");
		final String app_name = configvomapper.loadConfig("APP_NAME");
		final String order_id = orderId;
		
		ArrayList<LogEarnVO> places = new ArrayList<LogEarnVO>();
	
		if(orderId !=null){
			OrderVO orderVO = orderVOMapper.getOrderById(orderId);
			final String nick_name=memberService.getNickName(orderVO.getCreate_by());
			List<String> member_list =memberService.getShangXianMemberIdByOrderId(order_id);
			if(member_list.size()!=0){
				for(int i=0;i<member_list.size();i++){
					if(member_list.get(i)!=null){
						final List<LogEarnVO> list =(ArrayList<LogEarnVO>) moneyService.selectBuyGoodsPackageProfitAwardList(member_list.get(i),order_id);//
						
						final String memberId=member_list.get(i);
						//个推
						new Thread(new Runnable() {
							public void run() {
								if(memberId !=null){
									for(int j=0; j<list.size();j++){
										Map<String, Comparable> map = new HashMap<String, Comparable>();
										map.put("title", app_name);
										map.put("content", "您有一笔" + list.get(j).getEarn_money()+ "元收入");
										map.put("type", 2);
										PushUtil.getuiPushSingle(memberId, app_logo,app_name,
												"您有一笔" + list.get(j).getEarn_money()+ "元收入", "",JSON.toJSONString(map));
										//消息+1
										msgDao.updMemberMsg(memberId, "4");
										System.out.println("买套餐分润推送 (商品)推送 个推");
									}
								}
							}
						}).start();
						//公众号
						new Thread(new Runnable() {
							public void run() {
								for(int j=0; j<list.size();j++){
									StringBuffer buffer = new StringBuffer();
									if((list.get(j).getAward().indexOf("3,2")>-1) ||(list.get(j).getAward().indexOf("2,3")>-1) ||"2".equals(list.get(j).getAward())){
										//活力奖（2）+助理奖（3）
										buffer.append("您有一笔收益！").append("\n\n");	
										buffer.append("交易类型："+list.get(j).getAward_name()).append("\n");	
										buffer.append("对方账号："+nick_name).append("\n");	
										buffer.append("获得收益：￥"+list.get(j).getEarn_money()
												+"(本金￥"+list.get(j).getCapital_cash()
												
												+"+利润￥"+list.get(j).getProfit_cash()
												+"+购物专用金￥"+list.get(j).getBuy_cash()+")").append("\n\n");	
										buffer.append("<a href=\""+wechat_host+"/account_cash\">>>查看详情</a>");	
										String content =buffer.toString();
										wechatservice.sendWeChatMsgCommonMethod(memberId,content);
									}else if("4".equals(list.get(j).getAward())){
										buffer.append("您有一笔收益！").append("\n\n");	
										buffer.append("交易类型："+list.get(j).getAward_name()).append("\n");	
										buffer.append("对方账号："+nick_name).append("\n");	
										buffer.append("获得收益：￥"+list.get(j).getEarn_money()
												+"(利润￥"+list.get(j).getProfit_cash()
												+"+购物专用金￥"+list.get(j).getBuy_cash()+")").append("\n\n");	
										buffer.append("<a href=\""+wechat_host+"/account_cash\">>>查看详情</a>");	
										String content =buffer.toString();
										wechatservice.sendWeChatMsgCommonMethod(memberId,content);
									}else{
										buffer.append("您有一笔收益！").append("\n\n");	
										buffer.append("交易类型："+list.get(j).getAward_name()).append("\n");	
										buffer.append("对方账号："+nick_name).append("\n");	
										buffer.append("获得收益：￥"+list.get(j).getEarn_money()).append("\n\n");	
										buffer.append("<a href=\""+wechat_host+"/account_cash\">>>查看详情</a>");	
										String content =buffer.toString();
										wechatservice.sendWeChatMsgCommonMethod(memberId,content);
									}
									System.out.println("买套餐分润推送 (商品)推送 公众号");
								}
							}
						}).start();
					}
				}
			}
		}
	}
	/*
	 * 买套餐分润推送 (充劵)
	 */
	public void BuyGoodsPackageProfitByConn_no(String conn_no) {
		final String connNo = conn_no;
		final String wechat_host = configvomapper.loadConfig("WECHAT_HOST");
		
		final String app_logo = configvomapper.loadConfig("APP_LOGO");
		final String app_name = configvomapper.loadConfig("APP_NAME");
		
		ArrayList<LogEarnVO> places = new ArrayList<LogEarnVO>();
		String nick_name_=null;
		if(conn_no !=null){
			List<String> member_list = memberService.getShangXianMemberId(connNo);
			final String nick_name =nick_name_=memberService.getNickNameByConnNO(connNo);
			if(member_list.size()!=0){
				for(int i=0;i<member_list.size();i++){
					if(member_list.get(i)!=null){
						final List<LogEarnVO> list =(ArrayList<LogEarnVO>) moneyService.selectRechargeTicketAwardList(member_list.get(i),connNo);//
						final String memberId=member_list.get(i);
						
						//个推
						new Thread(new Runnable() {
							public void run() {
								if(memberId !=null){
									for(int j=0; j<list.size();j++){
										Map<String, Comparable> map = new HashMap<String, Comparable>();
										map.put("title", app_name);
										map.put("content", "您有一笔" + list.get(j).getEarn_money()+ "元收入");
										map.put("type", 2);
										PushUtil.getuiPushSingle(memberId, app_logo,app_name,
												"您有一笔" + list.get(j).getEarn_money()+ "元收入", "",JSON.toJSONString(map));
										//消息+1
										msgDao.updMemberMsg(memberId, "4");
										System.out.println("买套餐分润推送 (充劵)个推推送 ");
									}
								}
							}
						}).start();
						//公众号
						new Thread(new Runnable() {
							public void run() {
								for(int j=0; j<list.size();j++){
									StringBuffer buffer = new StringBuffer();
									if((list.get(j).getAward().indexOf("3,2")>-1) ||(list.get(j).getAward().indexOf("2,3")>-1) ||"2".equals(list.get(j).getAward())){
										//活力奖（2）+助理奖（3）
										buffer.append("您有一笔收益！").append("\n\n");	
										buffer.append("交易类型："+list.get(j).getAward_name()).append("\n");	
										buffer.append("对方账号："+nick_name).append("\n");	
										buffer.append("获得收益：￥"+list.get(j).getEarn_money()
												+"(本金￥"+list.get(j).getCapital_cash()
												+"+利润￥"+list.get(j).getProfit_cash()
												+"+购物专用金￥"+list.get(j).getBuy_cash()+")").append("\n\n");	
										buffer.append("<a href=\""+wechat_host+"/account_cash\">>>查看详情</a>");	
										String content =buffer.toString();
										wechatservice.sendWeChatMsgCommonMethod(memberId,content);
									}else if("4".equals(list.get(j).getAward())){
										buffer.append("您有一笔收益！").append("\n\n");	
										buffer.append("交易类型："+list.get(j).getAward_name()).append("\n");	
										buffer.append("对方账号："+nick_name).append("\n");	
										buffer.append("获得收益：￥"+list.get(j).getEarn_money()
												+"(利润￥"+list.get(j).getProfit_cash()
												+"+购物专用金￥"+list.get(j).getBuy_cash()+")").append("\n\n");	
										buffer.append("<a href=\""+wechat_host+"/account_cash\">>>查看详情</a>");	
										String content =buffer.toString();
										wechatservice.sendWeChatMsgCommonMethod(memberId,content);
									}else{
										buffer.append("您有一笔收益！").append("\n\n");	
										buffer.append("交易类型："+list.get(j).getAward_name()).append("\n");	
										buffer.append("对方账号："+nick_name).append("\n");	
										buffer.append("获得收益：￥"+list.get(j).getEarn_money()).append("\n\n");	
										buffer.append("<a href=\""+wechat_host+"/account_cash\">>>查看详情</a>");	
										String content =buffer.toString();
										wechatservice.sendWeChatMsgCommonMethod(memberId,content);
									}
									System.out.println("买套餐分润推送 (充劵)推送 公众号");
								}
							}
						}).start();
					}
				}
			}
		}
	}
	/*
	 * 退款 公众号推送  个推推送
	 */
	public void pushRefund(String total_price, String create_by,String type) {
		final String refund_fee = total_price;
		final String memberId = create_by;
		final String pay_type = type;
		final String wechat_host = configvomapper.loadConfig("WECHAT_HOST");
		final String app_logo = configvomapper.loadConfig("APP_LOGO");
		final String app_name = configvomapper.loadConfig("APP_NAME");
		
			if(!"0.00".equals(refund_fee)){//不等于购物赚佣金
				new Thread(new Runnable() {
					public void run() {
						StringBuffer buffer = new StringBuffer();
						buffer.append("您有一笔收益！").append("\n\n");	
						buffer.append("交易类型：退款").append("\n");	
						buffer.append("获得收益：￥"+refund_fee).append("\n");	
						if("4".equals(pay_type)){
							//购物赚佣金
							buffer.append("<a href=\""+wechat_host+"/account_buyCash\">>>查看详情</a>");	
						}else{
							buffer.append("<a href=\""+wechat_host+"/account_cash\">>>查看详情</a>");	
						}
						String content =buffer.toString();
						wechatservice.sendWeChatMsgCommonMethod(memberId,content);
					}
				}).start();
			}
		if(!"0.00".equals(refund_fee)){
			new Thread(new Runnable() {
				public void run() {
					Map<String, Comparable> map = new HashMap<String, Comparable>();
					map.put("title", app_name);
					map.put("content", "您有一笔" + refund_fee+ "元收入");
					map.put("type", 2);
					PushUtil.getuiPushSingle(memberId, app_logo,app_name,
							"您有一笔" + refund_fee+ "元收入", "",JSON.toJSONString(map));
				}
			}).start();
		}
	}

	/*
	 * 买套餐订单支付 公众号
	 */
	public void pushOrderPayOne(String id) {
		final String order_id = id;
		final String app_name = configvomapper.loadConfig("APP_NAME");
		final String wechat_host = configvomapper.loadConfig("WECHAT_HOST");
		final String ticket_name = configvomapper.loadConfig("TICKET_NAME");
		final OrderVO orderVO =orderService.getOrderById(order_id);
		final String good_name= orderService.getOrderGoodName(order_id);
		new Thread(new Runnable() {
			public void run() {
					
					
					DecimalFormat  df = new DecimalFormat("######0.00");   

					StringBuffer buffer = new StringBuffer();
					buffer.append("【"+app_name+"】订单支付成功！").append("\n\n");	
					//现金+商票
					if(!"0".equals(orderVO.getTotal_price())&&!"0".equals(orderVO.getTotal_ticket())){
						String total_price =df.format(Double.parseDouble(orderVO.getTotal_price())+Double.parseDouble(orderVO.getFreight()));
						buffer.append("订单金额：￥"+total_price+"+"+orderVO.getTotal_ticket()+ticket_name).append("\n");	
					}
					//现金
					if(!"0".equals(orderVO.getTotal_price())&&"0".equals(orderVO.getTotal_ticket())){
						String total_price =df.format(Double.parseDouble(orderVO.getTotal_price())+Double.parseDouble(orderVO.getFreight()));
						buffer.append("订单金额：￥"+total_price).append("\n");	
					}
					//商票
					if("0".equals(orderVO.getTotal_price())&&!"0".equals(orderVO.getTotal_ticket())){
						buffer.append("订单金额："+orderVO.getTotal_ticket()+ticket_name).append("\n");	
					}
					if(good_name.length()>15){
						String good_name1 = good_name.substring(0, 14)+"...";
						buffer.append("购买商品："+good_name1).append("\n");	
					}else{
						buffer.append("购买商品："+good_name).append("\n");	
					}
					buffer.append("收货信息："+orderVO.getAddress_name()+","+orderVO.getAddress_tel()+","+orderVO.getAddress_content()).append("\n");	
					buffer.append("订单编号："+orderVO.getNo()).append("\n\n");	
					buffer.append("<a href=\""+wechat_host+"/orderDetail?order_id="+orderVO.getId()+"\">>>查看详情</a>");	
					String content =buffer.toString();
					wechatservice.sendWeChatMsgCommonMethod(orderVO.getCreate_by(),content);
				}
		}).start();
		
	}
	
}
